package com.bank.manage.utils;


import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.gavin.core.enums.CommonStatus;
import org.gavin.core.exception.DataException;

import javax.crypto.Cipher;
import java.io.ByteArrayOutputStream;
import java.net.URLDecoder;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap;
import java.util.Map;

/**
 * RSA2Utils
 *
 * @author grl
 * @date 2022/9/7
 */
@Slf4j
public class Rsa2Utils {
    // 取值 SHA256WithRSA 或者 SHA1WithRSA
    // RSA 对应 SHA1WithRSA
    // RSA2 对应 SHA256WithRSA 至少2048 位以上
    public static final String SHA_WITH_RSA_ALGORITHM = "SHA256WithRSA";

    public static final String MD5_WITH_RSA = "MD5WithRSA";

    public static final int KEY_SIZE = 2048;

    public static final String ALGORITHM = "RSA";

    public static final String CHARSET = "UTF-8";

    /**
     * RSA最大加密明文大小
     */
    private static final int MAX_ENCRYPT_BLOCK = 245;
    /**
     * RSA最大解密密文大小
     */
    private static final int MAX_DECRYPT_BLOCK = 256;

    /**
     * SHAWithRSA签名
     */
    public static String sign(String in, String pivateKey, String algorithm) throws Exception {
        PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decodeBase64(pivateKey));
        KeyFactory keyf = KeyFactory.getInstance(ALGORITHM);
        PrivateKey priKey = keyf.generatePrivate(priPKCS8);
        Signature signa = Signature.getInstance(algorithm != null ? algorithm : SHA_WITH_RSA_ALGORITHM);
        signa.initSign(priKey);
        signa.update(in.getBytes());
        byte[] signdata = signa.sign();
        return Base64.encodeBase64String(signdata);
    }

    /**
     * SHAWithRSA签名 默认 SHAWithRSA签名
     */
    public static String sign(String in, String pivateKey) throws Exception {
        return sign(in, pivateKey, null);
    }

    /**
     * SHAWithRSA验签 默认SHAWithRSA验签
     */
    public static boolean isValid(String in, String signData, String publicKey, String algorithm) throws Exception {
        KeyFactory keyFactory = KeyFactory.getInstance(ALGORITHM);
        byte[] encodedKey = Base64.decodeBase64(publicKey);
        PublicKey pubKey = keyFactory.generatePublic(new X509EncodedKeySpec(encodedKey));
        Signature signa = Signature.getInstance(algorithm != null ? algorithm : SHA_WITH_RSA_ALGORITHM);
        signa.initVerify(pubKey);
        signa.update(in.getBytes());
        byte[] sign_byte = Base64.decodeBase64(signData);
        boolean flag = signa.verify(sign_byte);
        return flag;
    }

    /**
     * SHAWithRSA验签
     */
    public static boolean isValid(String in, String signData, String publicKey) throws Exception {
        return isValid(in, signData, publicKey, null);
    }

    /**
     * RSA2公钥加密
     */
    public static String encrypt(String str, String publicKey) throws Exception {
        // base64编码的公钥
        byte[] decoded = Base64.decodeBase64(publicKey);
        RSAPublicKey pubKey =
                (RSAPublicKey)KeyFactory.getInstance(ALGORITHM).generatePublic(new X509EncodedKeySpec(decoded));
        // RSA加密
        Cipher cipher = Cipher.getInstance(ALGORITHM);
        cipher.init(Cipher.ENCRYPT_MODE, pubKey);

        // 对数据分段加密
        byte[] data = str.getBytes();
        int inputLen = data.length;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int offSet = 0;
        byte[] cache;
        int i = 0;
        while (inputLen - offSet > 0) {
            if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
                cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK);
            } else {
                cache = cipher.doFinal(data, offSet, inputLen - offSet);
            }
            out.write(cache, 0, cache.length);
            i++;
            offSet = i * MAX_ENCRYPT_BLOCK;
        }
        byte[] encryptedData = out.toByteArray();
        out.close();
        String outStr = Base64.encodeBase64String(encryptedData);

        return outStr;
    }

    /**
     * RSA2私钥解密
     */
    public static String decrypt( String privateKey,String str){
       try {
           StringBuffer stringBuffer = new StringBuffer();
           if(str.contains(",")){
               String[] split = str.split(",");
               for(int a = 0 ; a < split.length ; a++){
                   String msg = getDecode(privateKey, split[a]);
                   stringBuffer.append(msg);
               }
           }else{
               String msg = getDecode(privateKey, str);
               stringBuffer.append(msg);
           }
           return URLDecoder.decode(stringBuffer.toString(),"UTF-8");
       } catch (Exception e) {
           log.error("Rsa2Utils decrypt URLDecoder.decode 失败 privateKey = {} , content = {}" ,privateKey ,str);
           throw DataException.le(CommonStatus.CIPHERTEXT_HANDLE_FAILED);
       }
    }


    public static String getDecode(String privateKey,String str){
        try{
            // 64位解码加密后的字符串
            byte[] inputByte = Base64.decodeBase64(str.getBytes(CHARSET));
            // base64编码的私钥
            byte[] decoded = Base64.decodeBase64(privateKey);
            RSAPrivateKey priKey =
                    (RSAPrivateKey)KeyFactory.getInstance(ALGORITHM).generatePrivate(new PKCS8EncodedKeySpec(decoded));
            // RSA解密
            Cipher cipher = Cipher.getInstance(ALGORITHM);
            cipher.init(Cipher.DECRYPT_MODE, priKey);

            // 对数据分段解密
            byte[] encryptedData = Base64.decodeBase64(str);
            int inputLen = encryptedData.length;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            int offSet = 0;
            byte[] cache;
            int i = 0;
            while (inputLen - offSet > 0) {
                if (inputLen - offSet > MAX_DECRYPT_BLOCK) {
                    cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK);
                } else {
                    cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet);
                }
                out.write(cache, 0, cache.length);
                i++;
                offSet = i * MAX_DECRYPT_BLOCK;
            }
            byte[] decryptedData = out.toByteArray();
            out.close();
            String outStr =  new String(decryptedData);
            return outStr;
        }catch (Exception e){
            log.error("Rsa2Utils decrypt 失败 privateKey = {} , content = {}" ,privateKey ,str);
            throw DataException.le(CommonStatus.CIPHERTEXT_HANDLE_FAILED);
        }
    }

    /**
     * 随机生成密钥对
     */
    public static  Map<String, String> genKeyPair() throws NoSuchAlgorithmException {
        Map<String, String> keyMap = new HashMap(2);
        // KeyPairGenerator类用于生成公钥和私钥对，基于RSA算法生成对象
        KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(ALGORITHM);
        // 初始化密钥对生成器，密钥大小为2048位
        keyPairGen.initialize(KEY_SIZE);
        // 生成一个密钥对，保存在keyPair中
        KeyPair keyPair = keyPairGen.generateKeyPair();
        // 得到私钥
        RSAPrivateKey privateKey = (RSAPrivateKey)keyPair.getPrivate();
        // 得到公钥
        RSAPublicKey publicKey = (RSAPublicKey)keyPair.getPublic();

        String publicKeyString =  java.util.Base64.getEncoder().encodeToString(publicKey.getEncoded());
        // 得到私钥字符串
        String privateKeyString = java.util.Base64.getEncoder().encodeToString(privateKey.getEncoded());
        // 将公钥和私钥保存到Map
        // 公钥
        keyMap.put("public", publicKeyString);
        // 私钥
        keyMap.put("private", privateKeyString);
        return keyMap;
    }
    /**
     * 随机生成密钥对
     */
    public static synchronized  Map<String, String> getPublicKey(HttpServletRequest request) throws NoSuchAlgorithmException {
         Map<String, String> keyMap = new HashMap(2);
        // KeyPairGenerator类用于生成公钥和私钥对，基于RSA算法生成对象
        KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(ALGORITHM);
        // 初始化密钥对生成器，密钥大小为2048位
        keyPairGen.initialize(KEY_SIZE, new SecureRandom());
        // 生成一个密钥对，保存在keyPair中
        KeyPair keyPair = keyPairGen.generateKeyPair();
        // 得到私钥
        RSAPrivateKey privateKey = (RSAPrivateKey)keyPair.getPrivate();
        // 得到公钥
        RSAPublicKey publicKey = (RSAPublicKey)keyPair.getPublic();

        String publicKeyString = Base64.encodeBase64String(publicKey.getEncoded());
        // 得到私钥字符串
        String privateKeyString = Base64.encodeBase64String(privateKey.getEncoded());
        // 将公钥和私钥保存到Map
        // 公钥
        keyMap.put("publicKey", publicKeyString);
        // 私钥
       //  keyMap.put("privateKey", privateKeyString);
        request.getSession().setAttribute("privateKey", privateKeyString);
        return keyMap;
    }

    /**
     * 随机生成密钥对
     */
    public static synchronized Map<String, String> getRsaKeyValue() throws NoSuchAlgorithmException {
        Map<String, String> keyMap = new HashMap(2);
        // KeyPairGenerator类用于生成公钥和私钥对，基于RSA算法生成对象
        KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(ALGORITHM);
        // 初始化密钥对生成器，密钥大小为2048位
        keyPairGen.initialize(KEY_SIZE, new SecureRandom());
        // 生成一个密钥对，保存在keyPair中
        KeyPair keyPair = keyPairGen.generateKeyPair();
        // 得到私钥
        RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
        // 得到公钥
        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();

        String publicKeyString = Base64.encodeBase64String(publicKey.getEncoded());
        // 得到私钥字符串
        String privateKeyString = Base64.encodeBase64String(privateKey.getEncoded());
        // 将公钥和私钥保存到Map
        // 公钥
        keyMap.put("publicKey", publicKeyString);
        // 私钥
        keyMap.put("privateKey", privateKeyString);
        return keyMap;
    }

    public Map<String, String>  getExponentAndModules(HttpServletRequest request) {
        Object obj = request.getSession().getAttribute("mapModules");
        if (obj != null) {
            return (Map<String, String>) obj;
        }
        Map<String, String> publicKey = null;
        try {
            publicKey = getPublicKey(request);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        request.getSession().setAttribute("mapModules", publicKey);
        return publicKey;
    }


    // 测试
//    public static void main(String[] args) throws Exception {
//        String content = "dahfaa老子最帅$";
//
//        System.out.println("字符串长度为："+content.getBytes().length);
//        Map<String, String> keyMap = genKeyPair();
//        String publicKey = keyMap.get("public");
//        String privateKey = keyMap.get("private");
//        System.out.println("public:" + publicKey);
//        System.out.println("public:" + privateKey);
//        /*加解密测试*/
//        String encryptContent = Rsa2Utils.encrypt(content, publicKey);
//        System.out.println("加密后数据:" + encryptContent);
//        String decryptContent = Rsa2Utils.decrypt(privateKey,encryptContent);
//        System.out.println("解密后数据:\n" + decryptContent);
//
//        /*加签验签测试*/
//        String signOriginalContent = "验签功能测试";
//        String geneSignContent = Rsa2Utils.sign(signOriginalContent, privateKey);
//        System.out.println("生成的签名:\n"+geneSignContent);
//        boolean valid = Rsa2Utils.isValid(signOriginalContent,geneSignContent, publicKey);
//        System.out.println("结果验签:\n"+valid);
//
//
//
//    }


    public static void main(String[] args) {
        String daima = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC9MRfVmS3TpzWKboiu+hv6eBaIcq7z8KdmzV+7JQO2YUXakIZ7xyRb57KqRVho14jtXfVfjHHg5ygXtEf90r2CZGvpkVal3swuSA/aZR0oYoc9quPeUgrY0ZSAL85owpPhfTwSCbntrPvtO+FNnskieKT/eLIADFOItwKzvIDNE7vfYxVsrurU6q8SmqAMz2jVP1/gvm1Trd0hRcUrVh74GnmKXyScpZ1fR3HjwBY4AWg85azn3zTahpdW1jFigu9IEufSB3UZtyEsBfkigcHQKd6BQh2Z/sl4PJY1fzw/Y3J9FdpTJ2VuVX96dQVJMzyFfox+icl7/E6S8RKzNg1BAgMBAAECggEABFyck/+pxD+ecvJGz5FruhXhD5zkwpIfmuW03X6+R9r04kPLHPEPuhh0uJscDWE8Onw8QSte0ACGTqsY7o24cahU6lPv6WeyQYYm6uoiPqVMYMgnBB/0OPDWhZDMl4LWZ9hEPXZ40VVn0r2q3Wgx8wvw4mSvBmQiXCRbgScxOUEfPe061o2ZymAQyqvH1E10ySpjw99FuaRQzMYlz0kNdRcilzVok+j7wM2ly9sdf0Zitx+wKkohv7F+EB3nXuw0c4h+opipY3O2D9LR88k2sIPI3s7Q43G65joNoMtFpUC3yUmbw6GNHGR083lfkSKihq5dmzcQTAyxqSqn7SLlwQKBgQDoTAFbYr+bxN7/47eP/4gElOpjk8s9DDRw5HrEbk9UNEb2nDO7lE3CvXrSJjhH3gTkUOSP3v54BtpaXn+HHuERkUTZ6DLb7UgFP28Am6d5symT9gp39bbdKNcuWJoQ6DfvAora98t4xPKt8OYGCrL69CGrdDoH8UQVxYt9SvXOoQKBgQDQfxuUZfeuCG9dxhInaKDIi2cSz87cYgaXDn6C/UkVT8gr1mAODAdN3u2HmzxUAk3tvZ4jRpBmRvDC7ecpBzTmmcRmZ5U2YvE1cFplD67A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icSg8Ht0VcsA+ObIYA7L3cvhJHWM7s7oWgLEy99s5";
        String redis = "";

        String value = "esLr+SVySOJ1YFi8/tQc84sEMzuu1gkcipUUolM7Z2PI1WWnCj0XVBf+ZRkJZd6rqthW46x2IKkdAg0ol9MGOGuJ5oqcDb4i5xq4gVddFLzbkyoyZQDWNH0Pkt6xEpSxUlZHVg0KtXoNNBYXvaR3v1soMG7ZaF3IzxfO0BykvANj0P4QEv1U2Y44RbgFhMHnMuB84may/jtX8aECrfZ6mGhxpkmRgBdTQzab+yrNIgtcY+8kvZ4h9csPOU6Oq8A8UL/RzQqF+aTvvkA+jFI1DeiZ+Fr/CXOXaUjUlpRW13bUHXqwrfFBSKV7UCb2ihhM4ztI8F1d1IhHtLny73qsJg==";
        String privatekey = "MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCXPIMe2oohpa6LCN41cXpfK5b2iT3MpLaL9OcRs5KcZPJnkNtAtK95xgAOvetZ6lPpEi749bMUbXxX+cCdvx4Inju57kgRv95SWolw1U0qy5qbTabtxbIGtCGzz2V98d4Qp1T43bRsyKTse9WWR35cPq5jzopHX253/uuRn6rwLJfHPokcQ+hh86OGBnISOMSqE//O2HfsQCzrXek8Ll+aFhhXtrf3e270innmqcs2UoygXYOnKJO6Vo1tANUQpYAi0T57qfu0PIysOTTZaI5SI5pL8TJxOPiz9UiUGGNJhsQKxCdMrrQaMe5ZNl5TkdgptlTfhykAB1lh1XEUE5x3AgMBAAECggEAdpSx0q1UBVHda5KGeK0DYD/TXHb7h8vWfiKGUzDT0eCs2FuSLkf+FqMTRHvRX20GYgcp4Xb09R1rk6d2SbmimOtItV6KD7C7ZyMqBNiaauW90euu6VxLXEo86rnBQGE21yP80i0z3N/twKbQL8ba4wUaw5MchR3khh3RIxtocmusrzD3RIFxPVBgYQ7VNDsvgGnOPEaV+8pSIiiSgZjH4r8nx0su4tpCjFv15Fz6WZcyKr9kjlzMvWEBiwntERAD72Zk2r3PUuLCqG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i4Grfbi8EuOnOzn4k/xpnYFDRdK2T6jb+2PGPLVlpBBCw5fOIxgcb/6Pu0d5HBUM9n+rtWNiaU+siU6EdPBKKr1Wkjuzc/qx6FMIqRCS3HAmx+8dsdcDR/n3WsqKUsAdzxyM3rkpWCsMU4/atVP+3UJS91cxLl3cnkPN1MeNJbn2iE3ZqQPRvz/TEJtynWm/I/nRRi5Iw1MMD8XZLust4+z7zSpH/Exm+S+ZD0t0dXZoq6OJZroQCUsD/QO5JqJzILZLkeQJTfwQ+WQIDAQAB";
        String randomkey = "1234567897882525667852";

            String decrypt = decrypt(privatekey, value);
            System.out.println(decrypt);
      /*    String sm4key = IdUtils.simpleUUID();
        String encrypt = encrypt(sm4key, publicKey);

        System.out.println("唯一值 "+encrypt);
        String bod = "{\n" +
                "\t\"userNum\":\"CGWSI2057007898HKU3M\",\n" +
                "\t\"clickEntry\":\"81tAPP-数字钱包\",\n" +
                "\t\"walletNum\":\"0041005655873123\",\n" +
                "\t\"accessDevice\":\"5400565587312341005655873123\",\n" +
                "\t\"accessDeviceInfo\":\"华为 Mate 40 Pro\"\n" +
                "}";

        String encryptEcb = GMSM4Utils.encryptEcb(bod, sm4key);
        System.out.println(encryptEcb);*/
        }
}
